package com.tony.demo.ui.performance.xnyh.memory;

import android.os.Bundle;
import androidx.annotation.Nullable;

import com.puhui.lib.utils.DMLog;
import com.tony.demo.R;
import com.tony.demo.mvp.presenter.impl.BasePresenter;
import com.tony.demo.ui.base.BaseActivity;

public class MemoryOptActivity extends BaseActivity {
    @Override
    protected BasePresenter createPresenter() {
        return null;
    }

    @Override
    protected int getViewLayout() {
        return R.layout.activity_test;
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

//        testObjectPool();

//        new MyAsyncTask().execute();
    }


    private void testObjectPool() {
        PersonPool personPool = new PersonPool(10);
        Person person1 = personPool.requestObj();
        Person person2 = personPool.requestObj();
        Person person3 = personPool.requestObj();
        Person person4 = personPool.requestObj();
        Person person5 = personPool.requestObj();
        Person person6 = personPool.requestObj();
        Person person7 = personPool.requestObj();
        Person person8 = personPool.requestObj();
        Person person9 = personPool.requestObj();
        Person person10 = personPool.requestObj();

        System.out.println("DMLog******" + person1);
        System.out.println("DMLog******" + person2);
        System.out.println("DMLog******" + person3);
        System.out.println("DMLog******" + person4);

        personPool.release(person2);
    }

//    public int computeFibonacci(int positionInFibSequence) {
//        //0 1 1 2 3 5 8
//        if (positionInFibSequence == 0) {  //??????
////            return 0;
////      } else if (positionInFibSequence <= 2) {
//            return 1;
//        } else {
//            return computeFibonacci(positionInFibSequence - 1)
//                    + computeFibonacci(positionInFibSequence - 2);
//        }
//    }

    /**
     * 优化后的斐波那契数列的非递归算法 caching缓存+批处理思想
     * 0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 ......
     */
    private void calculate() {
        int a = 0;
        int b = 1;
        int c;
        int i = 0;
        StringBuilder stringBuilder = new StringBuilder("0 1 ");
        while (i < 40) {
            c = b;
            b = a + b;
            a = c;
            i++;
            stringBuilder.append(b).append(" ");
        }
        DMLog.e(this.getClass().getCanonicalName(), stringBuilder.toString());
        DMLog.e(this.getClass().getCanonicalName(), "b = " + b + ",  a = " + a);
    }
}
